﻿using UnityEngine;
using System.Collections;

public class AsteroidContact : MonoBehaviour {

	public GameObject explosition;
	public GameObject playerExplosition;

	public int score;
	private XBGameController gameController;

	private Transform transform;

	void Start() {
		transform = GetComponent<Transform> ();
		GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
		if (gameControllerObject != null) {
			gameController = gameControllerObject.GetComponent<XBGameController> ();
		} else if (gameController == null) {
			Debug.Log ("Cannot find 'GameController' script");
		}
	}

	void OnTriggerEnter(Collider other) {
		if (other.tag == "Boundary")
			return;
		
		Destroy (other.gameObject);
		Destroy (gameObject);

		if (other.tag == "Player") {
			PlayPlayerExplosition ();
		} else {
			PlayExplosition ();
			gameController.AddScore(score);
		}
	}

	void PlayExplosition() {
		Instantiate (explosition, transform.position, transform.rotation);
	}

	void PlayPlayerExplosition() {
		Instantiate (playerExplosition, transform.position, transform.rotation);
	}
}
